const { getJSON } = require("jquery");

define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'detail/index' + location.search,
                    add_url: 'detail/add',
                    edit_url: 'detail/edit',
                    del_url: 'detail/del',
                    multi_url: 'detail/multi',
                    import_url: 'detail/import',
                    table: 'detail',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                searchFormVisible:true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'name', title: __('产品名'),operate: 'LIKE',},
                        {field: 'type_id', title: __('类型ID'),searchList:getJSON('detail/getTypeList')},
                        {field: 'typeName', title: __('类型名'),operate: false},
                        {field: 'guige_id', title: __('规格id'),operate: false},
                        {field: 'guigeName', title: __('规格名'),operate: false},
                        {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'money', title: __('Money'), operate:false},
                        {field: 'commend', title: __('是否推荐'), searchList: {"0":__('不推荐'),1:'推荐'}, formatter: Table.api.formatter.status},
                        {field: 'status', title: __('Status'), searchList: {"0":__('不展示'),1:'正常'}, formatter: Table.api.formatter.status},
                        {field: 'num', title: __('Num'),operate:false},
                        {field: 'create_time', title: __('Create_time'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'active', title: __('活动商品'), searchList: {"0":__('不是'),1:'是'}, formatter: Table.api.formatter.status},
                        {field: 'active_money', title: __('Active_money'), operate:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
               
            },
            
        }
    };
    return Controller;
});
